package com.idanchuang.component.just.web.config;

/**
 * @author yjy
 * @date 2019/12/11 11:37
 **/
public class ComponentConfig {

    /** 是否使用默认的异常信息 */
    private boolean useDefaultExceptionMessage;
    /**默认的异常信息 */
    private String defaultExceptionMessage;
    /** 全局异常日志描述 */
    private String globalExceptionLogTitle;
    /** 业务异常日志级别 */
    private String businessLogLevel;
    /** 是否打印业务异常的栈信息 */
    private boolean businessLogTrace;
    /** 透传用户信息的headerName */
    private String userHeaderName;
    /** 是否打印访问日志 */
    private boolean accessLog;
    /** 打印响应结果采样率 [0-1]**/
    private double logResultProbability;
    /** 是否打印响应结果 */
    private boolean logResult;
    /** 是否打印请求头 */
    private boolean logHeaders;
    /** 是否打印请求体 */
    private boolean logRequest;
    /** 是否开启全量录制 */
    private boolean logFull;
    /** 访问url的模板 */
    private String accessUrlPatterns;
    /** 忽略健康检查的访问日志 */
    private boolean ignoreLogHealth;
    /** 忽略静态资源请求 */
    private boolean ignoreLogResource;

    /** URL模板 */
    public static String[] accessUrlPatternList;

    {
        useDefaultExceptionMessage = true;
        defaultExceptionMessage = "服务开小差了, 请稍后再试";
        globalExceptionLogTitle = "GlobalExceptionHandler exception happened";
        businessLogLevel = "warn";
        businessLogTrace = false;
        userHeaderName = "userinfo";
        accessLog = false;
        logResult = false;
        logHeaders = false;
        logRequest = false;
        ignoreLogHealth = true;
        ignoreLogResource = false;
        logResultProbability = 0.01D;
    }

    public void setAccessUrlPatterns(String accessUrlPatterns) {
        if (accessUrlPatterns == null) {
            ComponentConfig.accessUrlPatternList = null;
            return;
        }
        this.accessUrlPatterns = accessUrlPatterns.replace(" ", "");
        ComponentConfig.accessUrlPatternList = this.accessUrlPatterns.split(",");
    }

    public String[] getAccessUrlPatternList() {
        return accessUrlPatternList;
    }

    public String getDefaultExceptionMessage() {
        return defaultExceptionMessage;
    }

    public boolean isUseDefaultExceptionMessage() {
        return useDefaultExceptionMessage;
    }

    public void setUseDefaultExceptionMessage(boolean useDefaultExceptionMessage) {
        this.useDefaultExceptionMessage = useDefaultExceptionMessage;
    }

    public boolean isAccessLog() {
        return accessLog;
    }

    public void setAccessLog(boolean accessLog) {
        this.accessLog = accessLog;
    }

    public void setDefaultExceptionMessage(String defaultExceptionMessage) {
        this.defaultExceptionMessage = defaultExceptionMessage;
    }

    public String getBusinessLogLevel() {
        return businessLogLevel;
    }

    public void setBusinessLogLevel(String businessLogLevel) {
        this.businessLogLevel = businessLogLevel;
    }

    public String getGlobalExceptionLogTitle() {
        return globalExceptionLogTitle;
    }

    public void setGlobalExceptionLogTitle(String globalExceptionLogTitle) {
        this.globalExceptionLogTitle = globalExceptionLogTitle;
    }

    public boolean isIgnoreLogHealth() {
        return ignoreLogHealth;
    }

    public boolean isIgnoreLogResource() {
        return ignoreLogResource;
    }

    public void setIgnoreLogResource(boolean ignoreLogResource) {
        this.ignoreLogResource = ignoreLogResource;
    }

    public boolean isLogResult() {
        return logResult;
    }

    public void setLogResult(boolean logResult) {
        this.logResult = logResult;
    }

    public void setIgnoreLogHealth(boolean ignoreLogHealth) {
        this.ignoreLogHealth = ignoreLogHealth;
    }

    public boolean getBusinessLogTrace() {
        return businessLogTrace;
    }

    public void setBusinessLogTrace(boolean businessLogTrace) {
        this.businessLogTrace = businessLogTrace;
    }

    public boolean isBusinessLogTrace() {
        return businessLogTrace;
    }

    public String getUserHeaderName() {
        return userHeaderName;
    }

    public void setUserHeaderName(String userHeaderName) {
        this.userHeaderName = userHeaderName;
    }

    public String getAccessUrlPatterns() {
        return accessUrlPatterns;
    }

    public boolean isLogHeaders() {
        return logHeaders;
    }

    public void setLogHeaders(boolean logHeaders) {
        this.logHeaders = logHeaders;
    }

    public boolean isLogRequest() {
        return logRequest;
    }

    public void setLogRequest(boolean logRequest) {
        this.logRequest = logRequest;
    }

    public boolean isLogFull() {
        return logFull;
    }

    public void setLogFull(boolean logFull) {
        this.logFull = logFull;
    }

    public double getLogResultProbability() {
        return logResultProbability;
    }

    public void setLogResultProbability(double logResultProbability) {
        this.logResultProbability = logResultProbability;
    }

    @Override
    public String toString() {
        return "ComponentConfig{" +
                "useDefaultExceptionMessage=" + useDefaultExceptionMessage +
                ", defaultExceptionMessage='" + defaultExceptionMessage + '\'' +
                ", globalExceptionLogTitle='" + globalExceptionLogTitle + '\'' +
                ", businessLogLevel='" + businessLogLevel + '\'' +
                ", businessLogTrace=" + businessLogTrace +
                ", userHeaderName='" + userHeaderName + '\'' +
                ", accessLog=" + accessLog +
                ", logResult=" + logResult +
                ", logHeaders=" + logHeaders +
                ", accessUrlPatterns='" + accessUrlPatterns + '\'' +
                ", ignoreLogHealth=" + ignoreLogHealth +
                ", ignoreLogResource=" + ignoreLogResource +
                '}';
    }
}
